package pers.feng1240.blog.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import pers.feng1240.blog.entities.Tag;
import pers.feng1240.blog.service.TagService;
import pers.feng1240.blog.util.PageHelper;

/*
 * 标签库
 */
@Controller
public class TagController {

	@Resource
	private TagService tagService;	//主题业务逻辑
	/*
	 * 添加标签
	 * @param theme
	 * @return
	 */
	@RequestMapping("admin/addTag")
	public String addTheme(Tag tag){	
		System.out.println(tag);
		tagService.addObject(tag);
		return "redirect:getTagList.do";
	}
	
	/*
	 * 获取分页列表
	 * @param pageIndex 要获取的页码
	 * @request map 中  objectList对象列表  pageIndex 要获取的页码  pageSize 页数
	 */
	@RequestMapping("admin/getTagList")
	public String getTagList(String pageIndex,HttpServletRequest request){	
		request.setAttribute("map", tagService.getPageList(PageHelper.pageIndex(pageIndex)));
		request.setAttribute("action","getTagList.do" ); //设置分页动态action
		return "forward:tag.jsp";
	}
	
	/*
	 * 标签列表json
	 */
	@RequestMapping("admin/getTagJson")
	@ResponseBody
	public List<Object> getTagJson(){
		return tagService.getObjectList();
	}
	/*
	 * 根据id获取标签
	 */
	@RequestMapping("admin/getTagById")
	@ResponseBody
	public Object getTagById(int id,HttpServletRequest request){
		return tagService.getById(id);
	}
	
	/*
	 * 修改
	 */
	@RequestMapping("admin/updateTag")
	public String updateTag(Tag tag){
		tagService.updateObject(tag);
		return "redirect:getTagList.do";
	}
	
	/*
	 * 删除
	 */
	@RequestMapping("admin/deleteTag")
	public String deleteOnject(int id){
		tagService.deleteById(id);
		return "redirect:getTagList.do";
	}
}
